package com.cssw.fyzb.tps.api.live;

import com.cssw.fyzb.tps.client.LiveClient;
import com.cssw.fyzb.tps.model.vo.OptLiveStreamVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Feng Chen
 */
@Function(description = "禁止直播流", parameters = {
        @Parameter(name = "app", type = Type.String, description = "推流路径", required = true),
        @Parameter(name = "stream", type = Type.String, description = "流名称", required = true),
        @Parameter(name = "day", type = Type.Integer, description = "禁播时间(单位天, 默认七天)", required = false),
        @Parameter(name = "reason", type = Type.String, description = "禁播原因", required = false),
}, result = @Result(properties = {
        @Property(name = "fileId", type = Type.String, description = "文件编号"),
        @Property(name = "mediaUrl", type = Type.String, description = "视频地址"),
        @Property(name = "coverUrl", type = Type.String, description = "封面地址"),
}))
@Component
public class ForbidLiveStream implements Action {

    @Autowired
    private LiveClient liveClient;

    private static final Logger logger = LoggerFactory.getLogger(ForbidLiveStream.class);

    @Override
    public Response execute(Request request) throws Exception {
        String app = request.getString("app");
        String stream = request.getString("stream");
        Integer day = request.getInteger("day");
        String reason = request.getString("reason");
        try {
            OptLiveStreamVo vo = liveClient.forbidLiveStream(app, stream, day, reason);
            return Response.success().put("data", vo);
        } catch (Exception e) {
            logger.error("", e);
        }
        return Response.fail("操作异常");
    }

}
